<%@ page import="inspur.dao.BookDao" %>
<%@ page import="inspur.entity.BookObject" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/22
  Time: 19:46
  网站主页
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="config.jsp"%>
<html>
<head>
    <title><%=webTitle%></title>
    <meta name="Keywords" content="<%=keywords%>">
    <meta name="Description" content="<%=Description%>">
    <link rel="stylesheet" href="css/style.css">
    <!--网站的ICO图标-->
    <link rel="shortcut icon" href="/favicon.ico"/>
    <link rel="bookmark" href="/favicon.ico"/>
    <script>
        //向console输出信息
        console.log("诚挚的邀请你加入我们，虽然目前只有我一个人在维护这个网站，但是还是希望更多的人能够参入进来");
        console.log("代码改善的建议，代码bug请反馈至：hyfree521@qq.com,标题：bug反馈-FormConsole");
    </script>
</head>
<body>
    <div align="center">
        <%@include file="component/top.jsp"%><!---顶栏-->
        <%@include file="component/checkBox.jsp"%><!--搜索框-->
        <%@include file="component/navigationPage.jsp"%><!--导航组件--->
        <div style="width: 1000px;margin: 0 auto;text-align: left">
            <%

                String id=request.getParameter("id");
                if (id==null){
                    response.sendRedirect("adoption.jsp");
                    return;
                }
                BookObject mybook=BookDao.SelectBookById(id);
                if (mybook==null){
                    response.sendRedirect("adoption.jsp");
                    return;
                }

            %>
            <p>书名：<%=mybook.getBookName()%></p><br>
            <p>出版社：<%=mybook.getPress()%></p><br>
            <p>介绍：<%=mybook.getIntroduction()%></p><br>
            <%
                if (mybook.getStatus().equals("0")){
            %>
            <hr>
                    <p>该书已经被<%=mybook.getUserid()%>借走</p>
                    <p>借书开始时间：<%=mybook.getStartDate()%></p>
                    <p>借书预约时间：<%=mybook.getUserTime()%></p>
                    <p>应该还书时间：<%=mybook.getReturnBoookTime()%></p>
            <hr><br><br>


            <%
                }
            %>
            <input class="bt500x50" id="BorrowBook" type="button" value="借书"><br><br>
            <input class="bt500x50" id="ReturnBook" type="button" value="还书"><br><br>
            <input class="bt500x50" id="DeleteBook" type="button" value="移除这本图书"><br><br>

            <script>
                function getUrlParam(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                    var r = window.location.search.substr(1).match(reg); //匹配目标参数
                    if (r != null) return unescape(r[2]); return null; //返回参数值
                }
              $("#BorrowBook").click(function () {
                    var bookid=getUrlParam("id");
                  $.post("BorrowBookServlet",{ bookId:bookid},function (data) {
                      if(data=="success"){
                          alert("借书图书成功。");
                          location.reload();
                      }else{
                          alert(data);
                      }
                  });

              });

                $("#ReturnBook").click(function () {
                    var bookid=getUrlParam("id");
                    $.post("ReturnBookServlet",{ bookId:bookid},function (data) {
                        if(data=="success"){
                            alert("还书图书成功。");
                            location.reload();
                        }else{
                            alert(data);
                        }
                    });

                });
                $("#DeleteBook").click(function () {

                    var bookid=getUrlParam("id");
                    $.post("DeleteBookServlet",{ bookId:bookid},function (data) {
                        if(data=="success"){
                            alert("移除图书成功。");
                            window.location.href="adoption.jsp";
                        }else{
                            alert(data);
                        }
                    });

                });
            </script>


        </div>
    </div>
</body>
</html>
